package db

import (
	"time"

	"gorm.io/gorm"
)

type RtimeAndUtime struct {
	Rtime     time.Time `gorm:"autoCreateTime"`
	RtimeText string    `gorm:"-" json:"rtime_text"`
	Utime     time.Time `gorm:"autoUpdateTime"`
	UtimeText string    `gorm:"-" json:"utime_text"`
}

func (r *RtimeAndUtime) AfterFind(tx *gorm.DB) error {
	r.RtimeText = r.Rtime.Format("2006-01-02 15:04:05")
	r.UtimeText = r.Utime.Format("2006-01-02 15:04:05")
	return nil
}

type Rtime struct {
	Rtime     time.Time `gorm:"autoCreateTime"`
	RtimeText string    `gorm:"-" json:"rtime_text"`
}

func (r *Rtime) AfterFind(tx *gorm.DB) error {
	r.RtimeText = r.Rtime.Format("2006-01-02 15:04:05")
	return nil
}

type Utime struct {
	Utime     time.Time `gorm:"autoUpdateTime"`
	UtimeText string    `gorm:"-" json:"utime_text"`
}

func (r *Utime) AfterFind(tx *gorm.DB) error {
	r.UtimeText = r.Utime.Format("2006-01-02 15:04:05")
	return nil
}
